var question_ispostnow = 0;   //是否提交
var question_jsonstr;         //获取的全局变量
var question_num = 1;         //当前的答题数
$(function(){
	//点击研发解药
	$(document).on("click",".btn_next_yf",function()
	{
		var callbackfunc = 'question_get_answer_callback';
		//暂略，测试弹出
		question_get_answer(this , callbackfunc);
	});
	//关闭问答
	$(document).on("click",".ans_close",function()
	{
		doctor_close_answer();
	});
	//选择答案
	$(document).on("click",".sel_now",function()
	{
		doctor_sel_answer(this);
	});
	//再答一次//
	$(document).on("click",".btn_next",function()
	{
		death();
		question_num = 1;  //清除次数
		doctor_close_answer();  //关闭题目弹层
		doctor_close_tips();   //关闭错误弹层
		var callbackfunc = 'question_get_answer_callback';
		//暂略，测试弹出
		question_get_answer(this , callbackfunc);
	});
	//应用解药
	$(document).on("click",".btn_next_use",function()
	{
		question_use_one(this);
	});
});

//提交获取问题内容
function question_get_answer(obj , callbackfunc)
{
	if(question_ispostnow == 0)
	{
		$('#questionid').val(1);  //初始化答题编号
		var posturl = 'http://www.jxapp.com:8080/game/getQuestion?quesCount=1';
		var poststr = '';
		question_ispostnow = 1;
		outjs_openwaiting();

		//这里需要提交单独项
		$.ajax({
		  type: 'GET',
		  url: posturl,
		  dataType: 'html',
		  data: poststr,
		  error: function () {
			  question_ispostnow = 0;
			  outjs_closewaiting();
		      outjs_openblock('请求失败，请重试！');
		  },
		  success: function (jsonhtml) {
              var question_jsonstr = "(" + jsonhtml + ")";
              question_obj = eval(question_jsonstr);
		      var callback = callbackfunc + '(' + "(" + jsonhtml + ")" + ')';
			  eval(callback);
		  }
		});
	}
	else
	{
		outjs_openblock('正在请求，请勿重复提交！');
	}
}

function question_get_answer_callback(obj)
{
	$('.ans_block').remove();  //移除上一个层
	question_ispostnow = 0;
	outjs_closewaiting();
	var n = question_num;  //第几题
	doctor_open_answer(obj , n);
}

//选择答案
function doctor_sel_answer(obj)
{
	var option = sysConfig.option;
	var isright = parseInt($(obj).attr('isright'));
	var n = question_num;  //第几题
	if(isright == 0)
	{
		//选错了！
		doctor_open_tips(isright , n);
	}
	else
	{
		//选对了
		if(question_num >= option.questionmaxnum)  //第三题，则给一粒解药
		{
			doctor_add_one();
			doctor_open_tips(isright , question_num);
		}
		else
		{
			question_num++;
			//再次获取一题
			var callbackfunc = 'question_get_answer_callback';
			//暂略，测试弹出
			question_get_answer(this , callbackfunc);
		}
	}
}

//增加解药
function doctor_add_one()
{
	sysConfig.option.elixir ++;
	updateElixir();
    outjs_openblock('特效药+1...');
}

//应用解药
function question_use_one()
{
	//把所有层关掉并清空数量
	question_num = 1;
	doctor_close_answer();
	doctor_close_tips();
	useElixir();
}
